package logic

import (
	"context"
	"yuekaoHouse/house_srv/model/mysql"

	"yuekaoHouse/house_srv/house"
	"yuekaoHouse/house_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type LoginByMobileCodeLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewLoginByMobileCodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginByMobileCodeLogic {
	return &LoginByMobileCodeLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *LoginByMobileCodeLogic) LoginByMobileCode(in *house.LoginByMobileCodeRequest) (*house.LoginByMobileCodeResponse, error) {
	// todo: 手机短信验证码登录

	h := mysql.House{}

	err := h.FindByMobileUserInfo(in.Mobile)
	if err != nil {
		logx.Error("手机号查询失败", err)
		return nil, err
	}
	return &house.LoginByMobileCodeResponse{UserID: int64(h.ID)}, nil
}
